package com.jsy.testlock.controller;


import com.jsy.testlock.service.ProductService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;

/**
 * (Product)表控制层
 *
 * @author: SongyangJi
 * @since: 2021-11-30 20:44:06
 * @description:
 */

@Slf4j
@RestController
@RequestMapping("product")
public class ProductController {
    /**
     * 服务对象
     */
    @Resource
    private ProductService productService;


    @PostMapping("/buy0/{id}")
    public boolean buyProductOverload(@PathVariable int id) {
        return productService.buyNonLock(id);
    }

    @PostMapping("/buy1/{id}")
    public boolean buyProductPessimistic(@PathVariable int id) {
        return productService.buyProductPessimistic(id);
    }

    @PostMapping("/buy2/{id}")
    public boolean buyProductOptimistic(@PathVariable int id) {
        return productService.buyProductOptimistic(id);
    }

    @PostMapping("/buy3/{id}")
    public boolean buyProductOptimisticWithRetry(@PathVariable int id) {
        return productService.buyProductOptimisticWithRetry(id);
    }

}
